from NCView.visualizers import VisualizationComponent
from Parser.file_adapters import FileAdapter


class VisualizationManager:
    def __init__(self):
        self.adapters = {}
        self.components = {}

    def register_adapter(self, file_type: str, adapter: FileAdapter):
        self.adapters[file_type] = adapter

    def register_component(self, data_type: str, component: VisualizationComponent):
        self.components[data_type] = component

    def visualize_file(self, file_path: str, file_type: str):
        adapter = self.adapters.get(file_type)
        if not adapter:
            raise ValueError(f"Unsupported file type: {file_type}")

        data = adapter.parse(file_path)
        component: VisualizationComponent = self.components.get(data["type"])
        if not component or component == "error":
            raise ValueError(f"No visualization component for type: {data['type']}")

        component.visualize(data["data"], {})